package org.vy.dal.dao.admin;

import java.util.ArrayList;
import java.util.List;

import org.vy.dal.QueryManager;

public class VyAdmModuleGroupDAO {
	private static final String FIND_BY_GROUP_CODE = "SELECT * FROM <TABLE> WHERE GROUP_CODE = m_groupCode";
	private static final String FIND_BY_MODULE_CODE = "SELECT * FROM <TABLE> WHERE MODULE_CODE = m_moduleCode";
	private static final String INSERT = "INSERT INTO <TABLE> (GROUP_CODE,MODULE_CODE,LAST_UPDATED_BY,LAST_UPDATED_ON) VALUES(m_groupCode,m_moduleCode,m_lastUpdatedBy,m_lastUpdatedOn)";
	private static final String DELETE_BY_MODULE_CODE = "DELETE FROM <TABLE> WHERE GROUP_CODE = m_groupCode";
	private static final String DELETE_BY_GROUP_CODE = "DELETE FROM <TABLE> WHERE MODULE_CODE = m_moduleCode";
	private static final String DELETE_BY_GROUP_AND_MODULE_CODE = "DELETE FROM <TABLE> WHERE GROUP_CODE = m_groupCode AND MODULE_CODE = m_moduleCode";

	@SuppressWarnings("unchecked")
	public static List<VyAdmModuleGroupDO> findByGroupCode(String key) throws Exception {
		VyAdmModuleGroupDO dto = new VyAdmModuleGroupDO();
		List<VyAdmModuleGroupDO> lst = new ArrayList<VyAdmModuleGroupDO>();
		dto.setGroupCode(key);
		lst = (List<VyAdmModuleGroupDO>)QueryManager.executeListQuery(dto, FIND_BY_GROUP_CODE);
		return lst;
	}

	@SuppressWarnings("unchecked")
	public static List<VyAdmModuleGroupDO> findByModuleCode(String key) throws Exception {
		VyAdmModuleGroupDO dto = new VyAdmModuleGroupDO();
		List<VyAdmModuleGroupDO> lst = new ArrayList<VyAdmModuleGroupDO>();
		dto.setModuleCode(key);
		lst = (List<VyAdmModuleGroupDO>)QueryManager.executeListQuery(dto, FIND_BY_MODULE_CODE);
		return lst;
	}

	public static VyAdmModuleGroupDO insert(VyAdmModuleGroupDO dto) throws Exception {

		dto = (VyAdmModuleGroupDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static boolean deleteByModuleCode(String key) throws Exception {
		VyAdmModuleGroupDO dto = new VyAdmModuleGroupDO();
		dto.setModuleCode(key);
		return QueryManager.executeDelete(dto, DELETE_BY_MODULE_CODE);
	}

	public static boolean deleteByGroupCode(String key) throws Exception {
		VyAdmModuleGroupDO dto = new VyAdmModuleGroupDO();
		dto.setGroupCode(key);
		return QueryManager.executeDelete(dto, DELETE_BY_GROUP_CODE);
	}

	public static boolean deleteByGroupAndModuleCode(String group, String module) throws Exception {
		VyAdmModuleGroupDO dto = new VyAdmModuleGroupDO();
		dto.setGroupCode(group);
		dto.setModuleCode(module);
		return QueryManager.executeDelete(dto, DELETE_BY_GROUP_AND_MODULE_CODE);
	}
}
